﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SomethingSpacial.LoginUI;
using SomethingSpacialClassLib.Web;
using System.ServiceModel.DomainServices.Client;


namespace SomethingSpacial.Views.MixItUp
{
    public partial class PrintBadgeRoom : UserControl
    {

        
        public PrintBadgeRoom()
        {
            InitializeComponent();

            this.Loaded += new RoutedEventHandler(PrintBadgeRoom_Loaded);

        }


        void PrintBadgeRoom_Loaded(object sender, RoutedEventArgs e)
        {

            WireUpStackedPanel();
            setMeetingDateTime();
        }


        void setMeetingDateTime()
        {


            var ctx = new SomethingSpacialContext();
            EntityQuery<Event> latestEventQuery = ctx.GetEventLatestQuery();
            var loadOperation = ctx.Load(latestEventQuery);


            if (!loadOperation.HasError)
                loadOperation.Completed += (s, ev) =>
                {
                    Event evt = loadOperation.Entities.SingleOrDefault();
                    if (evt != null)
                    {
                        textBlockEventDate.Text = evt.EVT_Start_Date.ToLongDateString();
                        textBlockEventTime.Text = evt.EVT_Start_Date.ToShortTimeString();
                    }
                };

        }

        #region Stacked Menu Interaction section (event capture and reaction)
        private void WireUpStackedPanel()
        {
            this.stackedMenu.OptionClickedEvent += new stackedMenuTest01_sl3.OptionClicked(stackedMenu_OptionClickedEvent);


        }

        void stackedMenu_OptionClickedEvent(string Option, EventArgs e)
        {
            //Execute click action for the option
            switch (Option)
            {
                case "0":
                    //Do something... child windows???
                    //print badge
                    openBadgePage();
                    break;

                case "1":
                    //directions
                    openDirectionsPage();
                    break;

                case "2":
                    //directions
                    openRafflePage();
                    break;

                default:
                    break;
            }
        }
        /*Option Selection Methods*/
        void openDirectionsPage()
        {
            PrintMapPage printDirectionsChildWindow = new PrintMapPage();
            printDirectionsChildWindow.Show();
        }

        void openRafflePage()
        {


            if (!AppServices.WebContext.Current.User.IsAuthenticated)
            {
                var loginWindow = new LoginRegistrationWindow();
                loginWindow.Show();

                loginWindow.Closed+=new EventHandler(ticketsLoginWindow_Closed);

            }
            else
            {
                PrintRafflePage printRaffleChildWindow = new PrintRafflePage();
                printRaffleChildWindow.Show();
            }

        }


        /*Option Selection Methods*/
        void openBadgePage()
        {

            if (true) //(!AppServices.WebContext.Current.User.IsAuthenticated)
            {
                var loginWindow = new LoginRegistrationWindow();
                loginWindow.Show();

                loginWindow.Closed += new EventHandler(loginWindow_Closed);

            }
            else
            {
                PrintBadgePage PrintBadgeChildWindow = new PrintBadgePage();
                PrintBadgeChildWindow.Show();
            }
        }


        void loginWindow_Closed(object sender, EventArgs e)
        {
            //if (AppServices.WebContext.Current.User.IsAuthenticated)
            //{
           

                
                
                PrintBadgePage PrintBadgeChildWindow = new PrintBadgePage();

                PrintBadgeChildWindow.Show();
            //}
        }



        void ticketsLoginWindow_Closed(object sender, EventArgs e)
        {
            if (AppServices.WebContext.Current.User.IsAuthenticated)
            {

                PrintRafflePage PrintRaffleTicketsChildWindow = new PrintRafflePage();

                PrintRaffleTicketsChildWindow.Show();
            }
        }

        #endregion Stacked Menu Interaction section (event capture and reaction)


    }
}
